﻿using System;
using System.Windows.Data;
using System.Globalization;

namespace Notoric.Gui.Converters
{
    /// <summary>
    /// Converts a double value in percents to its normalized value (division by 100)
    /// and back.
    /// </summary>
    [ValueConversion(typeof(double), typeof(double))]
    public class PercentageConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <inheritdoc/>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return ((double)value) / 100;
        }

        /// <inheritdoc/>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return ((double)value) * 100;
        }

        #endregion
    }
}
